package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.FormGroupFieldValueAddDTO;
import org.jsola.hr.dto.FormGroupFieldValueUpdateDTO;
import org.jsola.hr.entity.FormGroupFieldValueDO;
import org.jsola.hr.query.FormGroupFieldValueQuery;
import org.jsola.hr.service.IFormGroupFieldValueService;
import org.jsola.hr.vo.FormGroupFieldValueVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 自定义字段存值
 *
 * @author zhr
 */
@Component
public class FormGroupFieldValueTestHelper extends BaseTestHelper {
    
    @Autowired
    private IFormGroupFieldValueService formGroupFieldValueService;

    /**
     * 生成add测试数据
     * @return FormGroupFieldValueAddDTO
     */
    public FormGroupFieldValueAddDTO getFormGroupFieldValueAddDTO(){
        FormGroupFieldValueAddDTO formGroupFieldValueAddDTO = new FormGroupFieldValueAddDTO();
        formGroupFieldValueAddDTO.setFieldId(SafeKit.getLong(getRandomValue("bigint",11)));
        formGroupFieldValueAddDTO.setContent(getRandomValue("text",2147483647));
        formGroupFieldValueAddDTO.setSubjectType(getRandomValue("varchar",32));
        formGroupFieldValueAddDTO.setSubjectId(getRandomValue("varchar",32));
        return formGroupFieldValueAddDTO;
    }


    /**
     * 生成update测试数据
     * @return FormGroupFieldValueUpdateDTO
     */
    public FormGroupFieldValueUpdateDTO getFormGroupFieldValueUpdateDTO(FormGroupFieldValueVO formGroupFieldValueVO){
        return formGroupFieldValueService.selectDOById(formGroupFieldValueVO.getId(), SITE_ID).to(FormGroupFieldValueUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return FormGroupFieldValueQuery
     */
    public FormGroupFieldValueQuery getFormGroupFieldValueQuery() {
        FormGroupFieldValueQuery formGroupFieldValueQuery = new FormGroupFieldValueQuery();
        List<FormGroupFieldValueDO> formGroupFieldValueDOList = formGroupFieldValueService.list(new FormGroupFieldValueDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(formGroupFieldValueDOList)) {
            FormGroupFieldValueDO formGroupFieldValueDO = formGroupFieldValueDOList.get(0);
            formGroupFieldValueQuery = formGroupFieldValueDO.to(FormGroupFieldValueQuery.class);
        }
        return formGroupFieldValueQuery;
    }

    /**
     * 保存示例
     * @return FormGroupFieldValueVO
     */
    public FormGroupFieldValueVO saveFormGroupFieldValueExample(){
        FormGroupFieldValueAddDTO addDTO = this.getFormGroupFieldValueAddDTO();
        FormGroupFieldValueVO formGroupFieldValueVO = formGroupFieldValueService.save(addDTO,buildTokenUser());
        return formGroupFieldValueVO;
    }


}

